package com.cmas.platform.config.sensitiveWord;

import com.aidex.common.annotation.DataSource;
import com.aidex.common.enums.DataSourceType;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cmas.platform.domain.PlatformConfig;
import com.cmas.platform.service.PlatformConfigService;
import com.github.houbb.sensitive.word.api.IWordAllow;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @Author su
 * @Date 2023/4/14 17:44
 */
@Component
@DataSource(value = DataSourceType.SLAVE)
public class WhitelistWord implements IWordAllow {

    @Autowired
    private PlatformConfigService platformConfigService;


    /**
     * 允许的内容-返回的内容不被当做敏感词
     * @author binbin.hou
     * @since 0.0.13
     */
    @Override
    public List<String> allow() {
        PlatformConfig sensitiveWordWhite = platformConfigService
                .getOne(new QueryWrapper<PlatformConfig>().lambda()
                        .eq(PlatformConfig::getKey, "sensitive_word_whitelist"));
        return Arrays.asList(StringUtils.deleteWhitespace(sensitiveWordWhite.getValueString()).split(","));
    }
}
